package com.jy.project.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class CommonStringUtils {

    //["1","2","3","4"]
    public static  String  toStr(String[] strings){
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            stringBuilder.append("'");
            stringBuilder.append(strings[i]);
            stringBuilder.append("'");
            if (i<(strings.length-1)){
                stringBuilder.append(",");
            }
        }
        return  stringBuilder.toString();
    }

    //1,2,3,4
    public static  String  toStrNotQuotationMarks(String[] strings){
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            stringBuilder.append(strings[i]);
            if (i<(strings.length-1)){
                stringBuilder.append(",");
            }
        }
        return  stringBuilder.toString();
    }

    //["1","2","3","4"]
    public static  String  toStr(List<String> strings){
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i < strings.size(); i++) {
            stringBuilder.append("'");
            stringBuilder.append(strings.get(i));
            stringBuilder.append("'");
            if (i<(strings.size()-1)){
                stringBuilder.append(",");
            }
        }
        return  stringBuilder.toString();
    }

    public static  String  toStr(Set<Object> strings){

        List<String> list=new ArrayList<>();
        Iterator<Object> iterator = strings.iterator();
        while (iterator.hasNext()){
            Object next = iterator.next();
            if (next instanceof  String){
                list.add((String) next);
            }
        }
        return  toStr(list);
    }
}
